<%--
  Created by IntelliJ IDEA.
  User: MSI
  Date: 2022/5/7
  Time: 10:44
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="/static/css/font.css">
    <link rel="stylesheet" href="/static/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="/static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-body">

    <form class="layui-form">
        <div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="x-red">*</span>用户名ID
            </label>
            <div class="layui-input-inline">
                <input type="text" id="userId" name="userId" required=""
                       autocomplete="off" class="layui-input" onfocus=this.blur()>
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>

        <div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="x-red">*</span>用户名
            </label>
            <div class="layui-input-inline">
                <input type="text" id="name" name="name" required=""
                       autocomplete="off" class="layui-input" onfocus=this.blur()>
            </div>
            <div class="layui-form-mid layui-word-aux" >
                <span class="x-red">*</span>
            </div>
        </div>
        <div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="x-red">*</span>角色名称
            </label>
            <div class="layui-input-inline">
                <select name="main_id" id="main_id">
                    <option value="">请选择职位</option>
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>角色参数
            </label>
            <div class="layui-input-inline">
                <input type="text" id="roleParam" name="roleParam" required=""
                       autocomplete="off" class="layui-input" onfocus=this.blur()>
            </div>
        </div>
        <input type="hidden" id="roleId" name="roleId"></form>
        <div class="layui-form-item">
            <label  class="layui-form-label">
            </label>
            <button  onclick="updateUserRole()">
                修改
            </button>
        </div>
    </form>
</div>
<script>
    // layui.use(['form','layer'], function() {
    //     $ = layui.jquery;
    //     var form = layui.form
    //         , layer = layui.layer;
    //     form.on('submit(update)', function(data){
    //         console.log(data)
    //         var roleId = $("#main_id").find("option:selected").val();
    //         console.log(roleId);
    //         $.ajax({
    //             url:"/userRoleAjax/update",
    //             type:"post",
    //             contentType:"application/x-www-form-urlencoded",
    //             data:{"roleId":roleId,"id":data.id},
    //             success:function (rs) {
    //                 console.log(rs);
    //                 layer.alert(rs.info, {icon: 6}, function () {
    //                     if (rs.success) {
    //                         // 获得frame索引
    //                         var index = parent.layer.getFrameIndex(window.name);
    //                         //关闭当前frame
    //                         parent.layer.close(index);
    //                         //刷新
    //                         parent.window.loadData();
    //                     }
    //                 });
    //             }
    //         })
    //     });
    // });
    function loadRoleName(){
        $.ajax({
            url: '/roleAjax/list',
            dataType: 'json',
            type: 'post',
            contentType:"application/x-www-form-urlencoded",
            async:false,
            success: function (rs) {
                console.log(rs.data[0].roleName);
                for (var i = 0; i < rs.data.length; i++) {
                    $("#main_id").append("<option value='"+rs.data[i].roleId+"' >" + rs.data[i].roleName + "</option>");
                }
            }
        });
    }
    function updateUserRole(){
        var roleId = $("#main_id").find("option:selected").val();
        var userId = $("#userId").val();
        console.log(roleId);
        console.log(userId);
        $.ajax({
            url:"/userRoleAjax/update",
            type:"post",
            contentType:"application/x-www-form-urlencoded",
            data:{"roleId":roleId,"userId":userId},
            success:function (rs) {
                console.log(rs);
                layer.alert(rs.info, {icon: 6}, function () {
                    if (rs.success) {
                        // 获得frame索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.layer.close(index);
                        //刷新
                        parent.window.loadData();
                    }
                });
            }
        })
    };


        //监听提交
    //取本地存储的值
    function getLocalStorage(){
        $("#userId").val(localStorage.getItem("userId"));
        $("#name").val(localStorage.getItem("name"));
        $("#roleParam").val(localStorage.getItem("roleParam"));
    }
    $(function (){
        getLocalStorage();
        loadRoleName();
    })
</script>
<script>var _hmt = _hmt || []; (function() {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
})();</script>
</body>

</html>